/**
 * 
 */
package com.hector.meinewerk.client.view.widget.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hector.meinewerk.client.R;
import com.hector.meinewerk.model.Category;
import com.hector.meinewerk.utils.ImageLoader;


public class CatergoryView extends RelativeLayout{

	//Context	
	private Context mContext;
	
	//View
	private ImageView mImgAvatar;
	private TextView mTxtName;
	
	//Variable
	private Category mCatergory = new Category();
	private ImageLoader mImageLoader;
	
	public CatergoryView(Context context) {
		super(context);
		mContext = context;
		setupViews();
	}
	
	public CatergoryView(Context context, Category category) {
		super(context);
		mContext = context;
		mImageLoader = new ImageLoader(mContext);
		setupViews();
		setCatergory(category);
	}
	
	private void setupViews(){
		LayoutInflater inflater = LayoutInflater.from(mContext);
		inflater.inflate(R.layout.item_catergory, this, true);
		
		mImgAvatar = (ImageView) findViewById(R.id.avatar_catergory);
		mTxtName = (TextView) findViewById(R.id.catergory_name);
	}

	public Category getCatergory() {
		return mCatergory;
	}

	public void setCatergory(Category catergory) {
		if(catergory == null)
			return;
		
		this.mCatergory = catergory;
		this.setTag(catergory);
		updateUI();
	}
	
	public void updateUI(){
		mTxtName.setText(mCatergory.getName());
		if(!TextUtils.isEmpty(mCatergory.getAvatar())){
			mImageLoader.DisplayImage(mCatergory.getAvatar(), mImgAvatar);
		}
	}

}
